package dongze.com.ckdj.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import dongze.com.ckdj.R;
import dongze.com.ckdj.adapter.CheckInPagerAdapter;
import dongze.com.ckdj.dagger.component.VehicleComponent;
import dongze.com.ckdj.data.entity.response.InspectionSectionResponse;
import dongze.com.ckdj.fragment.custom.MartinVehicleInformationFragment;

/**
 * Created by fanqwz on 2017/7/20.
 */

public class PortInspectionFragment extends BaseFragment {
    @Inject
    InspectionSectionResponse mInspectionSection;

    @BindView(R.id.viewpager)
    ViewPager viewPager;

    BaseFragment mVehicleInformationFragment = new VehicleInformationFragment();
    //    CheckInRecordFragment mCheckInRecordFragment = new CheckInRecordFragment();
    BaseFragment mCheckInOperationFragment = new CheckInOperationFragment();

//    public void setOnCheckInOperationFinishedListener(CheckInOperationFragment.OnCheckInOperationFinishedListener listener) {
//        mCheckInOperationFragment.setOnCheckInOperationFinishedListener(listener);
//    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getComponent(VehicleComponent.class) != null) {
            getComponent(VehicleComponent.class).inject(this);

            if (TextUtils.equals(mInspectionSection.getBrand_code(), "15")/*aston martin*/) {
                mVehicleInformationFragment = new MartinVehicleInformationFragment();
            }
        } else {
            getFragmentManager().beginTransaction().remove(this).commit();
            return;
        }
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View root = inflater.inflate(R.layout.fragment_port_inspection, container, false);
        ButterKnife.bind(this, root);

        if (savedInstanceState == null) {
//            FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
//            fragmentTransaction.replace(R.id.infomation_container, mVehicleInformationFragment);
//            fragmentTransaction.replace(R.id.operation_container, mCheckInRecordFragment);
//            fragmentTransaction.replace(R.id.operation_container, mCheckInOperationFragment);
//            fragmentTransaction.commit();

            viewPager.setAdapter(new CheckInPagerAdapter(getChildFragmentManager(), mVehicleInformationFragment, mCheckInOperationFragment));
            viewPager.setCurrentItem(1);
        }

        return root;
    }
}
